<template>
  <div class="login-container">
    <div class="login-content">
      <div class="project-intro">
        <h1 class="project-title">多链钱包集成系统</h1>
        <div class="project-logo">
          <i class="el-icon-wallet logo-icon"></i>
        </div>
        <div class="project-description">
          <h3>系统简介</h3>
          <p>
            多链钱包集成系统是一个集成多种区块链网络的钱包管理平台，支持以太坊等主流区块链，为用户提供安全、便捷的数字资产管理服务。
          </p>
          <h3>核心功能</h3>
          <ul>
            <li><i class="el-icon-wallet feature-icon"></i> 多链钱包管理</li>
            <li>
              <i class="el-icon-picture-outline feature-icon"></i> NFT资产铸造
            </li>
            <li><i class="el-icon-document feature-icon"></i> 交易记录查询</li>
          </ul>
        </div>
      </div>
      <el-card class="login-card">
        <div slot="header" class="card-header">
          <h2>登录</h2>
        </div>
        <el-form
          :model="loginForm"
          :rules="rules"
          ref="loginForm"
          label-width="80px"
        >
          <el-form-item label="用户名" prop="username">
            <el-input
              v-model="loginForm.username"
              placeholder="请输入用户名"
            ></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input
              v-model="loginForm.password"
              type="password"
              placeholder="请输入密码"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              @click="submitForm"
              :loading="loading"
              style="width: 100%"
              >登录</el-button
            >
          </el-form-item>
          <div class="form-footer">
            <span>还没有账号？</span>
            <router-link to="/register">立即注册</router-link>
          </div>
        </el-form>
      </el-card>
    </div>
  </div>
</template>

<script>
import { mapActions } from "vuex";

export default {
  name: "Login",
  data() {
    return {
      loginForm: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
      loading: false,
    };
  },
  methods: {
    ...mapActions(["login"]),
    submitForm() {
      this.$refs.loginForm.validate(async (valid) => {
        if (valid) {
          try {
            this.loading = true;
            await this.login(this.loginForm);
            this.$message.success("登录成功");
            this.$router.push("/dashboard");
          } catch (error) {
            this.$message.error(error.response?.data?.message || "登录失败");
          } finally {
            this.loading = false;
          }
        }
      });
    },
  },
};
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f5f7fa;
}

.login-content {
  display: flex;
  width: 900px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  overflow: hidden;
  background-color: #fff;
}

.project-intro {
  flex: 1;
  padding: 30px;
  background-color: #409eff;
  color: white;
}

.project-title {
  font-size: 28px;
  margin-bottom: 20px;
  text-align: center;
}

.project-logo {
  text-align: center;
  margin: 30px 0;
}

.logo-icon {
  font-size: 80px;
}

.project-description {
  margin-top: 30px;
}

.project-description h3 {
  margin-top: 20px;
  margin-bottom: 10px;
  font-size: 18px;
}

.project-description p {
  line-height: 1.6;
  margin-bottom: 15px;
}

.project-description ul {
  list-style: none;
  padding-left: 0;
}

.project-description li {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
}

.feature-icon {
  margin-right: 10px;
  font-size: 18px;
}

.login-card {
  width: 400px;
  border: none;
  box-shadow: none;
}

.card-header {
  text-align: center;
}

.form-footer {
  text-align: center;
  margin-top: 15px;
  font-size: 14px;
}

.form-footer a {
  color: #409eff;
  margin-left: 5px;
}

@media screen and (max-width: 768px) {
  .login-content {
    flex-direction: column;
    width: 90%;
  }

  .project-intro {
    padding: 20px;
  }

  .login-card {
    width: 100%;
  }
}
</style>
